﻿using UnityEngine;
using UnityEngine.UI;

namespace MyGame
{
    public class BoardUI : BaseUI<BoardUI>
    {
        public const string title4 = "\n(点击返回开始菜单)";

        public Transform chessList;

        [Header("游戏结束说明")]
        public Text gameOver_info;

        [Header("游戏结束按钮")]
        public MyButton gameOver_button;
        protected override void Awake()
        {
            //注册菜单
            UIManager.Instance.RegisterMenu(uIType, gameObject);

            RegisterAction();        
        }

        private void Start()
        {
            ChessManager.Instance.InitMapSprite();

            Hide();
        }

        private void RegisterAction()
        {
            gameOver_button.myAction_Click += () =>
            {
                UIManager.Instance.GameOver();
            };

            gameOver_button.myAction_Enter += () =>
            {
                gameOver_button.myImage.color = Color.red;
            };

            gameOver_button.myAction_Exit += () =>
            {
                gameOver_button.myImage.color = Color.black;
            };
        }

        public void Init()
        {
            gameOver_button.gameObject.SetActive(false);
        }

        public void GamaOver(int winner)
        {
            gameOver_button.gameObject.SetActive(true);
            string endText = null;
            switch (winner)
            {
                case 1:
                    endText = "游戏结束，黑方胜利！";
                    break;
                case 2:
                    endText = "游戏结束，白方胜利！";
                    break;
                default:
                    break;
            }
            gameOver_info.text = endText + title4;
        }

        private void OnDestroy()
        {
            //注销菜单
            UIManager.Instance.UnregisterMenu(uIType);
        }
    }
}


